****
** Replication File for:
**
** The Partisan Contours of Rights and Liberties
**
** Miles Armaly and Adam Enders
**
** Political Behavior
****

set more off

* Import data
import delimited "Raw Data, March 2022.csv"

* Install "rowranks" 
*ssc install "rowranks"


****
** Recode and create variables
****

* Attention checks
gen pass1 = 0
replace pass1 = 1 if q23 == 3

gen pass2 = 0
replace pass2 = 1 if q28_5 == 23

gen pass3 = 0
replace pass3 = 1 if q34_5 == 11

gen pass4 = 0
replace pass4 = 1 if q37 == 1


keep if pass1 == 1 & pass2 == 1 & pass3 == 1 & pass4 == 1


* Time spent completing survey
gen short = 0
sum duration, d
* under 5% removed; < 6 minutes on 15 minute survey
replace short = 1 if duration < 353
drop if short == 1


* Generate unique ID
gene id = _n



*partisanship
gen pid = .
replace pid = 1 if q6 == 1
replace pid = 2 if q6 == 2
replace pid = 3 if q7 == 2
replace pid = 4 if q7 == 3 | q7 == 4
replace pid = 5 if q7 == 1
replace pid = 6 if q5 == 2
replace pid = 7 if q5 == 1

gen pidstrength = abs(pid - 4) + 1

gen rep = .
replace rep = 1 if pid > 4 & pid < .
replace rep = 0 if pid < 5

gen pid3cat = .
replace pid3cat = 1 if pid < 4
replace pid3cat = 2 if pid == 4
replace pid3cat = 3 if pid > 4 & pid < .


* Ideology
gen ideo = q8
replace ideo = . if q8 > 7

gen ideostrength = abs(ideo - 4) + 1

gen conserv = .
replace conserv = 1 if ideo > 4 & ideo < .
replace conserv = 0 if ideo < 5

gen ideo3cat = .
replace ideo3cat = 1 if ideo < 4
replace ideo3cat = 2 if ideo == 4
replace ideo3cat = 3 if ideo > 4 & ideo < .


* Interest in politics
gen interest = q45
recode interest (4=1) (3=2) (5=3) (2=4) (1=5)


* Participation in politics
egen participate = rowtotal(q46_1-q46_6)


* Age (categorical)
gen agecat = .
replace agecat = 1 if age >= 18 & age <= 24
replace agecat = 2 if age >= 25 & age <= 44
replace agecat = 3 if age >= 45 & age <= 64
replace agecat = 4 if age >= 65 & age < .


* Region
gen south = 0
replace south = 1 if region == 3


* Gender
gen female = 0
replace female = 1 if gender == 2


* Latinx
gen latinx = 0
replace latinx = 1 if hispanic > 1 & hispanic < 15


* Race
gen white = 0
replace white = 1 if ethnicity == 1

gen black = 0
replace black = 1 if ethnicity == 2

gen race = .
replace race = 1 if white == 1
replace race = 2 if black == 1
replace race = 3 if ethnicity >= 4 & ethnicity <= 14
replace race = 4 if ethnicity == 3 | ethnicity == 15


* Education
gen edu = education
replace edu = . if education < 1
recode edu (3=3) (4=3) (5=3) (6=4) (7=5) (8=5)


* Religious denominations
gen evangelical = 0
replace evangelical = 1 if q55 == 2

gen protestant = 0
replace protestant = 1 if q55 == 1

gen catholic = 0
replace catholic = 1 if q55 == 3

gen otherreligion = 0
replace otherreligion = 1 if q55 >=4 & q55 <= 6
replace otherreligion = 1 if q55 == 8 

gen nones = 0
replace nones = 1 if q55 == 7


* Religiosity
gen attend = (q56 * -1) + 6


* Income
gen income = hhi
replace income = . if hhi < 1


* Knowledge questions
gen know1 = .
replace know1 = 1 if q39 == 1
replace know1 = 0 if q39 > 1 & q39 <=5

gen know2 = .
replace know2 = 1 if q40 == 2
replace know2 = 0 if q40 == 1 | q40 == 4 | q40 == 5

gen know3 = .
replace know3 = 1 if q41 == 2
replace know3 = 0 if q41 == 1 | q41 == 3

gen know4 = .
replace know4 = 1 if q42 == 2
replace know4 = 0 if q42 == 1 | q42 == 3 | q42 == 4

gen know5 = 0
replace know5 = 1 if q43 == 6

gen know6 = 0
replace know6 = 1 if q44 == 10

alpha know1-know6, gen(knowledge)




* Right rankings variables
gen speech2 = q9_1
gen arms2 = q9_2
gen privacy2 = q9_3
gen religion2 = q9_6
gen press2 = q9_10


* Rights rankings from triads
rowranks speech2 arms2 privacy2 religion2 press2, ///
	generate(speech arms privacy religion press)
	
* How knowledgeable about US Constitution?
gen cknow = (q47 * -1) + 31


* How knowledgeable about rights and liberties guaranteed US Constitution?
gen rknow = (q48 * -1) + 26

* Rule of law
foreach var of varlist q30_1-q30_4{
	replace `var' = 6-`var'
}
alpha q30_1-q30_4, gen(ruleoflaw)

	
	
* What rights do you have?
mean q24_1-q24_11 q25_1-q25_11
factor q24_1-q24_11 q25_1-q25_11, ipf
fapara, reps(10) seed(123)
factor q24_1-q24_11 q25_1-q25_11, ipf factor(3)
rotate, promax blank(.2)
alpha  q24_1-q24_11 q25_1-q25_11, gen(possess)


* Who/what has violated rights?
rename q26_1 feds
rename q26_2 state
rename q26_3 police
rename q26_4 schools
rename q26_5 businsses
rename q26_6 others
rename q26_7 landlords
rename q26_8 banks
rename q26_9 employers
rename q26_10 socialmedia
rename q26_11 medical
rename q26_12 media

foreach var of varlist feds-media{
	recode `var' (7=3)
}

foreach var of varlist feds-media{
	gen `var'dk = 0
	replace `var'dk = 1 if `var' == 3
}

egen candk = rowmean(fedsdk-schoolsdk)
egen cannotdk = rowmean(businssesdk-mediadk)


* Which rights are threatened?
mean q27_1-q27_9
	
	
*saveold "Clean Data, March 2022.dta", version(12) replace

********************************************************************************

use "March 2022, with weights.dta", clear



****
** Table 1 
****

* full sample
mean speech [aweight=weight]
mean privacy [aweight=weight]
mean religion [aweight=weight]
mean arms [aweight=weight]
mean press [aweight=weight]

* democrats
mean speech [aweight=weight] if rep == 0 & pid != 4
mean privacy [aweight=weight] if rep == 0 & pid != 4
mean religion [aweight=weight] if rep == 0 & pid != 4
mean arms [aweight=weight] if rep == 0 & pid != 4
mean press [aweight=weight] if rep == 0 & pid != 4

mean speech [aweight=weight] if rep == 1 & pid != 4
mean privacy [aweight=weight] if rep == 1 & pid != 4
mean religion [aweight=weight] if rep == 1 & pid != 4
mean arms [aweight=weight] if rep == 1 & pid != 4
mean press [aweight=weight] if rep == 1 & pid != 4



****
** Figure 1 (stored in "Who Violated.csv")
****

* Proportion say violated 
foreach var of varlist feds-media{
	gen `var'3 = `var'
	recode `var'3 (3=0)(2=0)
}

* Democrats
mean feds3 [aweight=weight] if rep == 0
mean state3 [aweight=weight] if rep == 0
mean police3 [aweight=weight] if rep == 0
mean schools3 [aweight=weight] if rep == 0
mean businsses3 [aweight=weight] if rep == 0
mean others3 [aweight=weight] if rep == 0
mean landlords3 [aweight=weight] if rep == 0
mean banks3 [aweight=weight] if rep == 0
mean employers3 [aweight=weight] if rep == 0
mean socialmedia3 [aweight=weight] if rep == 0
mean medical3 [aweight=weight] if rep == 0
mean media3 [aweight=weight] if rep == 0

* Republicans
mean feds3 [aweight=weight] if rep == 1
mean state3 [aweight=weight] if rep == 1
mean police3 [aweight=weight] if rep == 1
mean schools3 [aweight=weight] if rep == 1
mean businsses3 [aweight=weight] if rep == 1
mean others3 [aweight=weight] if rep == 1
mean landlords3 [aweight=weight] if rep == 1
mean banks3 [aweight=weight] if rep == 1
mean employers3 [aweight=weight] if rep == 1
mean socialmedia3 [aweight=weight] if rep == 1
mean medical3 [aweight=weight] if rep == 1
mean media3 [aweight=weight] if rep == 1

********************************************************************************

****
** Table 2
****

* Generate pro-civil liberties
foreach var of varlist q33_1-q33_4{
	recode `var' (-7=1)(-6=2)(-5=3)(-4=2)(-5=1)
}

foreach var of varlist q34_1-q34_4{
	recode `var' (9=1)(10=2)(11=3)(12=4)(13=5)
}
drop procivil
alpha q33_1-q33_4 q34_1-q34_4, gen(procivil) reverse( q33_1-q33_4 q34_1-q34_4)

* Generate DVs
egen nongov = rowtotal(businsses3-media3)
replace nongov = nongov/8
egen gov = rowtotal(feds3-schools3)
replace gov = gov/4

* Rescale variables to range from 0-1
foreach var of varlist procivil pid ideo ruleoflaw interest attend age edu income {
  su `var', meanonly 
  gen `var'2 = (`var' - r(min))/(r(max) - r(min)) 
}

* Regressions
reg nongov pid2 ideo2 ruleoflaw2 procivil2 knowledge interest2 attend2 ///
	age2 edu2 income2 female black [aweight = weight], beta

reg gov pid2 ideo2 ruleoflaw2 procivil2 knowledge interest2 attend2 ///
	age2 edu2 income2 female black [aweight = weight], beta
 
********************************************************************************

****
** Figure 2 (stored in "Rights Threat.csv")
****

* Democrats
mean q27_1 [aweight=weight] if rep == 0
mean q27_2 [aweight=weight] if rep == 0
mean q27_3 [aweight=weight] if rep == 0
mean q27_4 [aweight=weight] if rep == 0
mean q27_5 [aweight=weight] if rep == 0
mean q27_6 [aweight=weight] if rep == 0
mean q27_7 [aweight=weight] if rep == 0
mean q27_8 [aweight=weight] if rep == 0
mean q27_9 [aweight=weight] if rep == 0

* Republicans
mean q27_1 [aweight=weight] if rep == 1
mean q27_2 [aweight=weight] if rep == 1
mean q27_3 [aweight=weight] if rep == 1
mean q27_4 [aweight=weight] if rep == 1
mean q27_5 [aweight=weight] if rep == 1
mean q27_6 [aweight=weight] if rep == 1
mean q27_7 [aweight=weight] if rep == 1
mean q27_8 [aweight=weight] if rep == 1
mean q27_9 [aweight=weight] if rep == 1

* Differences?
ttest q27_4, by(rep) unequal
ttest q27_6, by(rep) unequal

********************************************************************************

****
** Table 3
****

* Generate DV
alpha q27_1-q27_9, gen(threat)

sum threat, meanonly 
gen threat2 = (threat - r(min))/(r(max) - r(min)) 

* Regression
reg threat2 pid2 ideo2 ruleoflaw2 procivil2 knowledge interest2 attend2 ///
	age2 edu2 income2 female black [aweight = weight], beta

********************************************************************************

****
** Table A1
****

tab agecat
tab edu
tab female
tab white
tab black
tab latinx
tab region
tab pid3cat

tab agecat [aweight=weight]
tab edu [aweight=weight]
tab female [aweight=weight]
tab white [aweight=weight]
tab black [aweight=weight]
tab latinx [aweight=weight]
tab region [aweight=weight]
tab pid3cat [aweight=weight]

********************************************************************************

****
** Figure A1 (stored in "Who Violated, DK.csv")
****

* Democrats
mean fedsdk [aweight=weight] if rep == 0
mean statedk [aweight=weight] if rep == 0
mean policedk [aweight=weight] if rep == 0
mean schoolsdk [aweight=weight] if rep == 0
mean businssesdk [aweight=weight] if rep == 0
mean othersdk [aweight=weight] if rep == 0
mean landlordsdk [aweight=weight] if rep == 0
mean banksdk [aweight=weight] if rep == 0
mean employersdk [aweight=weight] if rep == 0
mean socialmediadk [aweight=weight] if rep == 0
mean medicaldk [aweight=weight] if rep == 0
mean mediadk [aweight=weight] if rep == 0

* Republicans
mean fedsdk [aweight=weight] if rep == 1
mean statedk [aweight=weight] if rep == 1
mean policedk [aweight=weight] if rep == 1
mean schoolsdk [aweight=weight] if rep == 1
mean businssesdk [aweight=weight] if rep == 1
mean othersdk [aweight=weight] if rep == 1
mean landlordsdk [aweight=weight] if rep == 1
mean banksdk [aweight=weight] if rep == 1
mean employersdk [aweight=weight] if rep == 1
mean socialmediadk [aweight=weight] if rep == 1
mean medicaldk [aweight=weight] if rep == 1
mean mediadk [aweight=weight] if rep == 1

* Differences?
prtest socialmediadk, by(rep)
prtest mediadk, by(rep)




********************************************************************************
** Regressions for violators and threat sections 
********************************************************************************

*** for appendix, because DVs are proportions 

logit nongov pid2 ideo2 ruleoflaw2 procivil2 knowledge interest2 attend2 age2 edu2 ///
  income2 female black 

logit gov pid2 ideo2 ruleoflaw2 procivil2 knowledge interest2 attend2 age2 edu2 ///
  income2 female black

********************************************************************************

